
import './App.css';
import React, { useEffect } from 'react';
import {
  BrowserRouter,
  Route,
  Switch
} from 'react-router-dom'
// import { isLogin, removeAduidInfo, removeDeviceIDInfo, removeUserInfo } from './utils/storage';

// const Login = React.lazy(()=> import('@/pages/Login'))
// const Home = React.lazy(()=> import('@/pages/Home'))

import Login from '@/pages/Login/login';
import { Redirect } from 'react-router-dom/cjs/react-router-dom.min';
import Launch from './pages/Launch';
import FingerprintJS from '@fingerprintjs/fingerprintjs'
import DeviceID from './utils/deviceId';
// import { generateAudid } from './utils/aduid';
// import { useDispatch } from 'react-redux';
// import LoginAd from './pages/LoginAd';
import AddHomeEvent from './utils/addHomeEvent';
import InstallApp from './pages/Login/InstallApp';
import AboutUs from './pages/AboutUs/AboutUs';
import TermsOfUse from './pages/TermsOfUse/TermsOfUse';
import Chat from './pages/Chat/Chat';
import ZjcCreate from './pages/Zjc/zjcCreate';
import ZjcVerify from './pages/Zjc/zjcVerify';
import ZjcInput from './pages/Zjc/zjcInput';
import Home from './pages/Home/home';
import Receive from './pages/Receive/receive';
import Invite from './pages/Invite/invite';
import Me from './pages/Me/me';
import MeTerms from './pages/Me/meTerms';
import MeAboutUs from './pages/Me/meAboutUs';
import MeSetting from './pages/Me/meSetting';
import MyWalletList from './pages/MyWallet/myWalletList';
import MyWalletManage from './pages/MyWallet/myWalletManage';
import Transfer from './pages/Transfer/transfer';
import TransferResult from './pages/Transfer/transferResult';
import AssetDetail from './pages/AssetDetail/assetDetail';
import AssetDetailResult from './pages/AssetDetail/assetDetailResult';
import Earn from './pages/Earn/earn';
import Withdraw from './pages/Earn/withdraw';
import WithdrawForInvite from './pages/Earn/withdrawForInvite';
import WithdrawResult from './pages/Earn/withdrawResult';
import InviteDetail from './pages/Earn/inviteDetail';
import TodayEarn from './pages/Earn/todayEarn';
import TodayEarnDetail from './pages/Earn/todayEarnDetail';
import TodayEarnDetailWithdrawTimes from './pages/Earn/todayEarnDetailWithdrawTimes';
import InviteEarnRules from './pages/Earn/inviteEarnRules';
import TodayEarnRules from './pages/Earn/todayEarnRules';
import Register from './pages/Login/register';

function App() {

  //移除登录信息
  // removeUserInfo()

  //上报aduid

  //获取 Redux 分发器
  // const dispatch = useDispatch()


  //初始化指纹
  useEffect(() => {

    //移除登录信息
    // removeUserInfo()
    // removeAduidInfo()
    // removeDeviceIDInfo()

    //初始化 aduid
    // const gAduid = DeviceID.getAduid()
    // console.log("启动初始化 gaudid: " + gAduid)

    //初始化 设备id
    if (!DeviceID.isValidVistorId()) {
      //初始化
      const fpPromise = FingerprintJS.load()

      //获取设备id
      fpPromise
        .then(fp => fp.get())
        .then(result => {
          DeviceID.saveVisitorId(result.visitorId)
          console.log("启动初始化 fingerprint: " + result.visitorId)

          //保存aduid
          //doSaveAduid()
        })
    } else {
      //保存aduid
      //doSaveAduid()
    }

    // //监听安装事件
    // AddHomeEvent.addBeforeInstallPromptEventListener()

    //注册service worker
    // if ('serviceWorker' in navigator) {
    //   navigator.serviceWorker.register('/service-worker.js')
    //     .then(function (registration) {
    //       console.log('Service Worker registered with scope:', registration.scope);
    //     })
    //     .catch(function (error) {
    //       console.error('Service Worker registration failed:', error);
    //     });
    // }

  }, [])

  return (
    <BrowserRouter basename="/vietnam">
      <div className="AppRoot">
        <div className="App">
          <Switch>
            <Route path='/launch' ><Launch /></Route>
            <Route path="/register"><Register /></Route>
            <Route path="/login"><Login /></Route>
            <Route path="/aboutus"><AboutUs /></Route>
            <Route path="/termsofuse"><TermsOfUse /></Route>
            <Route path="/chat"><Chat /></Route>

            <Route path="/installapp"><InstallApp /></Route>

            <Route path="/zjccreate"><ZjcCreate /></Route>
            <Route path="/zjcverify"><ZjcVerify /></Route>
            <Route path="/zjcinput"><ZjcInput /></Route>

            <Route path="/home"><Home /></Route>
            <Route path="/receive"><Receive /></Route>
            <Route path="/invite"><Invite /></Route>
            <Route path="/me"><Me /></Route>
            <Route path="/metermsofuse"><MeTerms /></Route>
            <Route path="/meaboutus"><MeAboutUs /></Route>
            <Route path="/mesetting"><MeSetting /></Route>

            <Route path="/mywalletlist"><MyWalletList /></Route>
            <Route path="/mywalletmanage"><MyWalletManage /></Route>

            <Route path="/transfer"><Transfer /></Route>
            <Route path="/transferresult"><TransferResult /></Route>

            <Route path="/assetdetail"><AssetDetail /></Route>
            <Route path="/assetdetailresult"><AssetDetailResult /></Route>

            <Route path="/earn"><Earn /></Route>
            <Route path="/withdraw"><Withdraw /></Route>
            <Route path="/withdrawforinvite"><WithdrawForInvite /></Route>
            <Route path="/withdrawresult"><WithdrawResult /></Route>
            <Route path="/invitedetail"><InviteDetail /></Route>
            <Route path="/todayearn"><TodayEarn /></Route>
            <Route path="/todayearndetail"><TodayEarnDetail /></Route>
            <Route path="/todayearndetailwithdrawtimes"><TodayEarnDetailWithdrawTimes /></Route>
            <Route path="/inviteearnrules"><InviteEarnRules /></Route>
            <Route path="/todayearnrules"><TodayEarnRules /></Route>


            {/* 直接去启动页 */}
            <Redirect to='/launch'></Redirect>

          </Switch>
        </div>
      </div>
    </BrowserRouter>
  );
}

export default App;
